package com.htgd.gardenexpo.controller;

import com.htgd.gardenexpo.entity.CommonResult;
import com.htgd.gardenexpo.entity.*;
import com.htgd.gardenexpo.service.GePhoneComplaintsService;
import io.swagger.annotations.Api;
import net.sf.json.JSONObject;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author ：hejing
 * @date ：Created in 2021/7/23 14:05
 * @description：投诉举报手机号管理
 * @menu: 投诉举报手机号管理
 * @modified By：`
 * @version: 1.0
 */
@Api(tags = "投诉举报手机号管理")
@RestController
@RequestMapping(value = "/api/phone")
public class ComplaintsPhoneController {
    @Resource
    private GePhoneComplaintsService gePhoneComplaintsService;

    /**
     * 添加投诉举报手机号
     */
    @PostMapping(value = "/add")
    public CommonResult<JSONObject> add(@RequestBody GePhoneComplaints gePhoneComplaints){
        CommonResult<JSONObject> result = new CommonResult<>();
        try {
            gePhoneComplaintsService.insert(gePhoneComplaints);
            result.setCode(200);
        }catch (Exception e){
            e.printStackTrace();
            result.setCode(500);
        }
        return result;
    }
    /**
     * 编辑投诉举报手机号
     */
    @PostMapping(value = "/edit")
    public CommonResult<JSONObject> edit(@RequestBody GePhoneComplaints gePhoneComplaints){
        CommonResult<JSONObject> result = new CommonResult<>();
        try {
            gePhoneComplaintsService.update(gePhoneComplaints);
            result.setCode(200);
        }catch (Exception e){
            e.printStackTrace();
            result.setCode(500);
        }
        return result;
    }

    /**
     * 删除投诉举报电话
     */
    @PostMapping(value = "/delete")
    public CommonResult<JSONObject> delete(int id){
        CommonResult<JSONObject> result = new CommonResult<>();
        try {
            gePhoneComplaintsService.deleteById(id);
            result.setCode(200);
        }catch (Exception e){
            e.printStackTrace();
            result.setCode(500);
        }
        return result;
    }

    /**
     * 获取投诉举报电话
     */
    @GetMapping(value = "/details")
    public CommonResult<GePhoneComplaints> details(){
        CommonResult<GePhoneComplaints> result = new CommonResult<>();
        try {
            List<GePhoneComplaints> list=gePhoneComplaintsService.queryAllByLimit(0,0);
            if (list!=null&&list.size()>0){
                result.setData(list.get(0));
            }
            result.setCode(200);
        }catch (Exception e){
            e.printStackTrace();
            result.setCode(500);
        }
        return result;
    }

}
